package com.wfc.servlet.user;

import com.wfc.entity.User;
import com.wfc.service.UserService;
import com.wfc.service.serviceImpl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/hello")
public class CharuServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("这是get请求");

    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String userName=req.getParameter("username");
        String password=req.getParameter("password");
        resp.setContentType("text/html;charset=utf-8");
        User user = new User();
        user.setUsername(userName);
        user.setPassword(password);
        UserService userService = new UserServiceImpl();
        System.out.println(user.getUsername()+user.getPassword());
        PrintWriter printWriter=resp.getWriter();
        String rep = "";
        if(userService.ServiceSinsertNews(user)) {
            rep="1";
        }
        printWriter.println(rep);

        printWriter.flush();
        printWriter.close();

       /* if (newsDao1.add(news)){
//            resp.sendRedirect("");
            req.getRequestDispatcher("index2.jsp").forward(req,resp);
            //resp.sendRedirect(req.getContextPath()+"/index2.jsp");
        }else {
            System.out.println("sddsdfs");
        }*/
    }
}
